<template>
  <div id="contain">
    <div>
      <el-table
        :data="tableList"
        style="width: 945px"
        stripe
        :row-style="rowStyle"
        :cell-style="cellStyle"
      >
        <el-table-column prop="name" label="景点名" align="center">
        </el-table-column>
        <el-table-column prop="address" label="地址" align="center">
        </el-table-column>
        <el-table-column prop="loginName" label="发布者账号" align="center">
        </el-table-column>
        <el-table-column prop="status" label="状态" align="center">
        </el-table-column>
        <el-table-column label="操作" align="center"  width="220">
          <template slot-scope="scope">
            <el-button type="mini" @click="edit(scope.row)">查看</el-button>
            <el-button size="mini" type="primary" @click="pass(scope.row)"
              >通过</el-button
            >
            <el-button type="mini" style="color: red" @click="clear(scope.row)"
              >不通过</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="block">
      <el-pagination
        :current-page.sync="page"
        :page-sizes="[10, 20]"
        :page-size="limit"
        layout="sizes, prev, pager, next"
        :total="totalCount"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
      </el-pagination>
    </div>
    <el-dialog title="编辑景点信息" :visible.sync="dialogFormVisible">
      <el-form ref="form" :model="form" label-width="100px">
        <el-form-item label="景点名称" style="width: 500px">
          <el-input v-model="form.name" disabled></el-input>
        </el-form-item>
        <el-form-item label="地址" style="width: 500px">
          <el-input v-model="form.address" disabled></el-input>
        </el-form-item>
        <el-form-item label="景点图片">
          <img
            :src="form.pic"
            alt="图片加载失败"
            style="width: 380px; height: 220px"
          />
        </el-form-item>
        <el-form-item label="景点介绍">
          <el-input
            type="textarea"
            :rows="8"
            v-model="form.introduction"
            disabled
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="this.dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      token: window.localStorage.getItem("token"),
      tableList: [],
      page: 1,
      limit: 10,
      totalCount: 0,
      dialogFormVisible: false,
      form: {},
    };
  },
  mounted() {
    this.fn();
  },
  methods: {
    fn() {
      this.$axios({
        method: "post",
        url: "/sys/msg/scenic",
        headers: { token: this.token },
      }).then((res) => {
        //   console.log('申请景点');
        //   console.log(res);
        //   console.log(res.data.page);
        if (res.data.code !== 0) {
          this.$message.error(res.data.msg);
          return false;
        }
        this.tableList = res.data.page;
        this.totalCount = this.tableList.length;
        this.tableList.forEach((item) => {
          item.status =
            item.status === 1
              ? "审核通过"
              : item.status === 0
              ? "未审核"
              : "未通过或撤销";
        });
        // console.log(this.tableList);
      });
    },
    handleSizeChange(val) {
      this.limit = val;
      this.fn();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.fn();
    },
    rowStyle() {
      return { height: "60px" };
    },
    cellStyle(k) {
      if (k.columnIndex === 4) {
        if (k.row.status === "审核通过") {
          return { color: "#33CC00" };
        } else if (k.row.status === "未审核") {
          return { color: "blue" };
        } else {
          return { color: "red" };
        }
      }
      if (k.columnIndex === 3) {
        if (k.row.roleId === "旅客") {
          return { color: "#3399FF" };
        } else if (k.row.roleId === "商家") {
          return { color: "#FFCC00" };
        } else {
          return { color: "#FF6600" };
        }
      }
    },
    pass(k) {
      // console.log(k.areaId);
      this.$axios({
        method: "post",
        url: "/sys/msg/scenic/status",
        headers: { token: this.token },
        data: { areaId: k.areaId, status: 1 },
      }).then((res) => {
        //   console.log(res);
        if (res.data.code !== 0) {
          this.$message.error(res.data.msg);
          return false;
        }
        if (res.data.code === 0) {
          this.fn();
        }
      });
    },
    edit(k) {
      this.form = k;
      this.dialogFormVisible = true;
      // console.log('form');
      // console.log(this.form);
    },
    clear(k) {
      let id = k.areaId;
      this.$axios({
        method: "post",
        url: "/scenicarea/del",
        headers: { token: this.token },
        data: { areaId: id },
      }).then((res) => {
        // console.log(res);
        if (res.data.code === 0) {
          this.$message({
            type: "success",
            message: "删除成功！",
          });
          this.fn();
        }
      });
    },
  },
};
</script>
<style  scoped>
</style>>
